package com.aerospace.serviceprovider.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8886);//建立服务端，ip为本机Ip,端口为8886
        Socket accept = serverSocket.accept();//监听客户端的连接，一旦有客户端连接，则返回客户端对应的accept
        InputStream in = accept.getInputStream();//获取到客户端的输出流
        byte b[] = new byte[1024];
        int len = in.read(b);
        System.out.println("接受到客户端数据，返回数据"+new String(b,0,len));
        OutputStream out = accept.getOutputStream();
        out.write("服务端已经接受".getBytes());//给客户端发送消息
        serverSocket.close();
    }
}
